﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DATN.Business;
using DATN.Common;

namespace DATN
{
    public partial class ListLichCongTacs : System.Web.UI.Page
    {
        public int _hoursMo = 1;
        public int _hoursSu = 1;
        public int _hoursSa = 1;
        public int _hoursFr = 1;
        public int _hoursTh = 1;
        public int _hoursWe = 1;
        public int _hoursTu = 1;
        public static DateTime _NgayDauTuan;
        public int _thuTuTuan;
        public static DateTime currentDate;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                currentDate = DateTime.Now;
                LoadAllDate();
            }

        }

        public void GetAllMo(string moDate)
        {
            LichCongTacBusiness business = new LichCongTacBusiness();
            DataListMonday.DataSource = business.GetAllLichCongTacByDate(moDate);
            DataListMonday.DataBind();
            _hoursMo = DataListMonday.Items.Count + 1;
        }

        public void GetAllTu(string tuDate)
        {
            LichCongTacBusiness business = new LichCongTacBusiness();
            DataListTu.DataSource = business.GetAllLichCongTacByDate(tuDate);
            DataListTu.DataBind();
            _hoursTu = DataListTu.Items.Count + 1;
        }

        public void GetAllWe(string weDate)
        {
            LichCongTacBusiness business = new LichCongTacBusiness();
            DataListWe.DataSource = business.GetAllLichCongTacByDate(weDate);
            DataListWe.DataBind();
            _hoursWe = DataListWe.Items.Count + 1;
        }

        public void GetAllTh(string thDate)
        {
            LichCongTacBusiness business = new LichCongTacBusiness();
            DataListTh.DataSource = business.GetAllLichCongTacByDate(thDate);
            DataListTh.DataBind();
            _hoursTh = DataListTh.Items.Count + 1;
        }

        public void GetAllFr(string frDate)
        {
            LichCongTacBusiness business = new LichCongTacBusiness();
            DataListFr.DataSource = business.GetAllLichCongTacByDate(frDate);
            DataListFr.DataBind();
            _hoursFr = DataListFr.Items.Count + 1;
        }

        public void GetAllSa(string saDate)
        {
            LichCongTacBusiness business = new LichCongTacBusiness();
            DataListSa.DataSource = business.GetAllLichCongTacByDate(saDate);
            DataListSa.DataBind();
            _hoursSa = DataListSa.Items.Count + 1;
        }

        public void GetAllSu(string suDate)
        {
            LichCongTacBusiness business = new LichCongTacBusiness();
            DataListSu.DataSource = business.GetAllLichCongTacByDate(suDate);
            DataListSu.DataBind();
            _hoursSu = DataListSu.Items.Count + 1;
        }

        protected void linkTuanTruoc_Click(object sender, EventArgs e)
        {
            currentDate = DateTime.Now.AddDays(-7);
        }

        protected void linkTuanSau_Click(object sender, EventArgs e)
        {
            currentDate = DateTime.Now.AddDays(7);
        }

        protected void btnTuanTruoc_Click(object sender, EventArgs e)
        {
            currentDate = currentDate.AddDays(-7);
            LoadAllDate();
        }

        protected void btnTuanSau_Click(object sender, EventArgs e)
        {
            currentDate = currentDate.AddDays(7);
            LoadAllDate();
        }

        public void LoadAllDate()
        {
            Utility.GetWeekInYear(currentDate, out _NgayDauTuan, out _thuTuTuan);
            GetAllMo(_NgayDauTuan.ToShortDateString());
            MoDate.Text = _NgayDauTuan.ToShortDateString();

            GetAllTu(_NgayDauTuan.AddDays(1).ToShortDateString());
            TuDate.Text = _NgayDauTuan.AddDays(1).ToShortDateString();

            GetAllWe(_NgayDauTuan.AddDays(2).ToShortDateString());
            WeDate.Text = _NgayDauTuan.AddDays(2).ToShortDateString();

            GetAllTh(_NgayDauTuan.AddDays(3).ToShortDateString());
            ThDate.Text = _NgayDauTuan.AddDays(3).ToShortDateString();

            GetAllFr(_NgayDauTuan.AddDays(4).ToShortDateString());
            FrDate.Text = _NgayDauTuan.AddDays(4).ToShortDateString();

            GetAllSa(_NgayDauTuan.AddDays(5).ToShortDateString());
            SaDate.Text = _NgayDauTuan.AddDays(5).ToShortDateString();

            GetAllSu(_NgayDauTuan.AddDays(6).ToShortDateString());
            SuDate.Text = _NgayDauTuan.AddDays(6).ToShortDateString();

            FromWeek.Text = _NgayDauTuan.ToShortDateString();
            ToWeek.Text = _NgayDauTuan.AddDays(6).ToShortDateString();
        }
    }
}